package com.chencong.online.function;

import com.chencong.online.bean.UserBehaviorBean;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.triggers.TriggerResult;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;

/**
 * @program: user-behavior-analysis-online
 * @ClassName UVTriggerFunc
 * @description:自定义触发器。
 * @author: chencong
 * @create: 2021-12-28 16:18
 **/
public class UVTriggerFunc extends Trigger<UserBehaviorBean, TimeWindow> {

    @Override
    public TriggerResult onElement(UserBehaviorBean element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception {
        //每一条数据来都会触发一次窗口计算，并且直接清空窗口
        return TriggerResult.FIRE_AND_PURGE;
    }

    @Override
    public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext ctx) throws Exception {
        return TriggerResult.CONTINUE;
    }

    @Override
    public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext ctx) throws Exception {
        return TriggerResult.CONTINUE;
    }

    @Override
    public void clear(TimeWindow window, TriggerContext ctx) throws Exception {

    }
}
